﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Strom.Client.GUI
{
    public partial class FormCreateCharacter : Form, Core.Graphic.ICreateCharacterForm
    {
        public FormCreateCharacter()
        {
            InitializeComponent();
            ClientManager.GUI.CreateCharacter = this;
        }

        protected override void OnClosed(EventArgs e)
        {
            ClientManager.GUI.CreateCharacter = null;
            base.OnClosed(e);
        }

        private void txt_name_TextChanged(object sender, EventArgs e)
        {
            btn_create.Enabled = txt_name.Text.Length != 0;
        }

        private void FormCreateCharacter_Load(object sender, EventArgs e)
        {
            Network.Parser.SetCreateCharacterForm(this);
        }

        public void CreateSuccess()
        {
            MessageBox.Show("Votre personnage a été créé.", "Strøm", MessageBoxButtons.OK, MessageBoxIcon.Information);
            ClientManager.GUI.CharactersSelection.AddNewCharacter(txt_name.Text);
            Close();
        }

        public void CreateFailed()
        {
            MessageBox.Show("Ce nom est déjà pris.", "Strøm", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            btn_create.Enabled = true;
            txt_name.Enabled = true;
        }

        private void btn_create_Click(object sender, EventArgs e)
        {
            btn_create.Enabled = false;
            txt_name.Enabled = false;
            new Core.Network.Packets.CreateCharacterRequestPacket().Pack(ClientManager.Client.Client, txt_name.Text);
        }
    }
}
